﻿#region
/* ===============================================
 * 作者：guopeng           时间：2012/2/2 21:47:15
 * 
 * 
 * 类描述：
 * 
 * 
 * =============================================== */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using CollegeShop.Tool.Framework;

namespace CollegeShop.Infrastructure.Entities
{
    public class DeleteContext<T> : ModityContext<T>
    {
        private Context context = null;
        public DeleteContext(Context ctx)
        {
            this.context = ctx;
            this.tableName = typeof(T).Name;
        }

        public override int Excute()
        {
            string sqlScript = String.Format("DELETE {0} {1}", tableName, wheresentence);
            try
            {
                LogHelper.Write(CommonLogger.ExServer, LogLevel.Trace, "使用扩展Linq执行Delete操作，执行语句：" + sqlScript);
                return context.Database.ExecuteSqlCommand(sqlScript);
            }
            catch (SqlException e)
            {
                LogHelper.Write(CommonLogger.ExServer, LogLevel.Error, e);
                return 0;
            }
        }
    }
}
